package org.scboy.common;

import org.scboy.common.interceptors.LoggerInterceptor;
import org.scboy.common.properties.CommonProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableConfigurationProperties(CommonProperties.class)
public class CommonWebMvcConfigurer implements WebMvcConfigurer{

	@Autowired
	CommonProperties properties;
	
	@Bean
	public LoggerInterceptor getLoggerInterceptor() {
		return new LoggerInterceptor();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(getLoggerInterceptor()).addPathPatterns("/**").excludePathPatterns(properties.getIgnorePath());
	}
}
